<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form>
                    <p:panel header="Search All Bill Items" >
                        <h:panelGrid columns="1" >
                            <h:panelGroup >
                                <p:panelGrid columns="6" >
                                    <h:inputText autocomplete="off" style="width: 600px;" id="txtSearch" value="#{opdBillItemsearch.txtSearch}" >
                                        <f:ajax render="tblBills" execute="txtSearch fromDate toDate" event="keyup" />
                                    </h:inputText>

                                    <h:outputLabel value="From Date"/>
                                    <p:calendar  id="fromDate" value="#{opdBillItemsearch.fromDate}"  pattern="dd MMMM yyyy hh mm a" >
                                        <p:ajax event="dateSelect" process="fromDate"  update="tblBills"/>
                                    </p:calendar>

                                    <h:outputLabel value="To Date"/>
                                    <p:calendar id="toDate" value="#{opdBillItemsearch.toDate}" navigator="true" pattern="dd MMMM yyyy hh mm a" >
                                        <p:ajax event="dateSelect" process="toDate"  update="tblBills"/>
                                    </p:calendar>


                                    <p:watermark  value="Search by Bill Id (with or without letters), Patient Name, Investigation name or Phone Number" for="txtSearch" />

                                </p:panelGrid>

                                <p:dataTable  id="tblBills" rowIndexVar="i" value="#{opdBillItemsearch.billItemsAll}" var="pi"  >
                                    <p:column headerText="No" styleClass="alignTop">
                                        <h:outputLabel value="#{i+1}"/>
                                    </p:column>
                                    
                                    <p:column headerText="Bill No" styleClass="alignTop" >
                                        #{pi.bill.insId}
                                        <br/>
                                        #{pi.bill.institution.name}
                                    </p:column>

                                    <p:column headerText="Patient"  styleClass="alignTop" >
                                        <h:outputLabel value="#{pi.bill.patient.person.nameWithTitle}" >
                                        </h:outputLabel>
                                        &nbsp;&nbsp;&nbsp;&nbsp;
                                        <h:commandLink value="(edit)" action="patient" >
                                            <f:setPropertyActionListener value="#{pi.bill.patient}" target="#{patientController.current}"/>
                                        </h:commandLink>
                                        <br/>
                                        <h:outputLabel value="#{pi.bill.patient.age}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="#{pi.bill.patient.person.sex}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="#{pi.bill.patient.person.phone}" >
                                        </h:outputLabel>
                                    </p:column>

                                    <p:column headerText="Investigation/Service"  styleClass="alignTop" >
                                        <h:outputLabel value="#{pi.item.name}" >
                                        </h:outputLabel>
                                        <br/>
                                        <h:outputLabel value="Billed at " />
                                        <h:outputLabel value="#{pi.bill.createdAt}" >
                                            <f:convertDateTime pattern="dd MMM yyyy hh mm a"/>
                                        </h:outputLabel>
                                        <br/>
                                        
                                        <h:panelGroup rendered="#{pi.bill.cancelled}" >
                                            <h:outputLabel style="color: red;" value="Cancelled at " />
                                            <h:outputLabel style="color: red;" rendered="#{pi.bill.cancelled}" value="#{pi.bill.cancelledBill.createdAt}" >
                                            <f:convertDateTime pattern="dd MMM yyyy hh mm a"/>
                                        </h:outputLabel>
                                        </h:panelGroup>
                                        <h:panelGroup rendered="#{pi.refunded}" >
                                            <h:outputLabel style="color: red;" value="Refunded at " />
                                            <h:outputLabel style="color: red;" rendered="#{pi.refunded}" value="#{pi.referanceBillItem.bill.createdAt}" >
                                            <f:convertDateTime pattern="dd MMM yyyy hh mm a"/>
                                        </h:outputLabel>
                                        </h:panelGroup>
                                        <br/>
                                    </p:column>

                                </p:dataTable>
                            </h:panelGroup>
                        </h:panelGrid>
                    </p:panel>

                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
